package clases.extras;

import java.util.ArrayList;

import aidi.shop.R;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;

public class ArrayAdapterProductos extends BaseAdapter {

	protected Activity Activity;
	protected ArrayList<ItemProductos> itemProd;

	public ArrayAdapterProductos(Activity activity, ArrayList<ItemProductos> items) {
		this.Activity = activity;
		this.itemProd = items;
	}

	public int getCount() {
		return itemProd.size();
	}

	public Object getItem(int position) {
		return itemProd.get(position);
	}

	public long getItemId(int position) {
		return itemProd.get(position).getIdProductos();
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		View vi = convertView;
		ViewHolder holder;

		if (vi == null) {
			LayoutInflater inflater = (LayoutInflater) Activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			vi = inflater.inflate(R.layout.item_producto, null);

			holder = new ViewHolder();
			holder.nombreProducto = (CheckBox) vi.findViewById(R.id.nombreProducto);

			vi.setTag(holder);

		}

		else {
			holder = (ViewHolder) vi.getTag();
		}

		ItemProductos item = this.itemProd.get(position);

		ImageView image = (ImageView) vi.findViewById(R.id.logoProducto);
		int imageResource = this.Activity.getResources().getIdentifier(
				item.getRutaLogo(), null, this.Activity.getPackageName());
		image.setImageDrawable(this.Activity.getResources().getDrawable(imageResource));

		holder.nombreProducto.setText(item.getNombreProductos());

		return vi;
	}

	static class ViewHolder {
		public CheckBox nombreProducto;
	

	}


}
